
<include file="Common:__head__"/>
<div class="permissions-tabs">
    <a class="role tabs-bg" href="{:U('Express/index')}">运费模板</a>
</div>
<div class="permissions-content">
    <div class="permissions-le">
        <span class="add-admin"><a href="javascript:history.go(-1)"></a>添加区域</span>
        <div class="message-set">
            <span class="hints">操作提示</span>
            <span class="hints-dec">请正确添加配送区域，方便准确匹配运费地址</span>
        </div>
        <form method="post" id="area_form" action="{:U('Express/addArea')}" enctype="multipart/form-data" name="form1">
            <input type="hidden" name="areas" id="areas" value=""/>
            <div class="add-admin-ipt">
                <span><i>*</i>区域名称:</span>
                <div class="add-admin-opt">
                    <input type="text" placeholder="名称" class="input-txt" name="ea_name" id="ea_name">
                    <p class="notic">配送区域名称必需填写</p>
                </div>
            </div>
            <div class="add-admin-ipt">
                <span><i>*</i>运费衡量标准:</span>
                <div class="add-admin-opt">
                    <input type="text" placeholder="重量单位为kg" class="input-txt" name="standard" id="standard" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')">
                    <p class="notic">填写衡量标准（重量）</p>
                </div>
            </div>
            <div class="add-admin-ipt">
                <span><i>*</i>标准重量以上:</span>
                <div class="add-admin-opt">
                    <input type="text" placeholder="运费单位为元/KG" class="input-txt" name="up_num" id="up_num" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')">
                    <p class="notic">填写标准重量以上每KG所需金额</p>
                </div>
            </div>
            <div class="add-admin-ipt">
                <span><i>*</i>标准重量以下:</span>
                <div class="add-admin-opt">
                    <input type="text" placeholder="运费单位为元/KG" class="input-txt" name="down_num" id="down_num" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')">
                    <p class="notic">填写标准重量以下每KG所需金额</p>
                </div>
            </div>
            <div class="add-admin-ipta">
                <span><i></i>区域:</span>
                <div class="add-admin-opta">
                    <div class="myarea"></div>
                </div>
            </div>
            <div class="add-admin-ipt">
                <span><i></i>服务平台:</span>
                <div class="add-admin-opt">
                    <div data-toggle="distpicker">
                    <select class="select" id="provice" size="6" style="width:160px;height:150px;float:left"></select>
                    <select class="select" id="city" size="6" style="width:160px;height:150px;float:left"></select>
                        <a class="btn btn-blue" id="confirm">确认</a>
                    </div>
                </div>
            </div>
            <div class="add-admin-ipt">
                <span></span>
                <input type="hidden" name="id" value="{$id}">
                <input type="submit" id="submitBtn" value="保存" class="sbm"/>
            </div>
        </form>
    </div>
    <div class="permissions-ri">
        <a href="" class="permissions-help">帮助和服务</a>
    </div>
</div>
<script type="text/javascript" src="__PUBLIC__/plugins/distpicker/js/distpicker.data.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugins/distpicker/js/distpicker.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugins/distpicker/js/main.js"></script>
<script>
    $(function(){
        $('#confirm').click(function () {
            var flag = false;
            var city = $("#city option:selected").val();
            var provice = $("#provice option:selected").val();

            $('input[name="regions[]"]').each(function() {
                var region = $(this).val();
                if(city==''){
                    if(provice == region){
                        flag = true;
                    }
                }
                if (city == region) {
                    flag = true;
                }
            })
            if(flag == true){
                layer.alert('此区域已经已经添加！');
                return false;
            }
            if(provice == ''){
                return false;
            }
            if((provice !== '')&&(city == '')){
                $('.myarea').append(provice+"<input type='checkbox' name='regions[]' value="+provice+" checked='true' value="+provice+">&nbsp;&nbsp;")
            }
            if((provice !=='')&&(city!=='')){
                $('.myarea').append(city+"<input type='checkbox' name='regions[]' value="+city+" checked='true' value="+city+">&nbsp;&nbsp;")
            }
        });

        $('#submitBtn').click(function () {
            var areas = val = '';
            $('input[name="regions[]"]:checked').each(function(){
                val = $(this).val();
                areas += (val+',');
                $("#areas").val(areas);
            });
            if (areas == '') {
                layer.alert('请添加区域！');
                return false;
            }
            var ea_name = $("#ea_name").val();
            var standard = $("#standard").val();
            var up_num = $("#up_num").val();
            var down_num = $("#down_num").val();

            if(!ea_name){
                layer.alert('请填写区域名称！');
                return false;
            }
            if(!standard){
                layer.alert('请填写运费衡量标准！');
                return false;
            }
            if(!up_num){
                layer.alert('请填写标准重量以上金额！');
                return false;
            }
            if(!down_num){
                layer.alert('请填写标准重量以下金额！');
                return false;
            }

            $("#area_form").submit();
        });
    });
</script>
<include file="common:__foot__"/>
